package com.gk.panda.apis.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.dto.EventToDoListSearchDto;
import com.gk.panda.apis.entity.eventtodo.dto.AcceptanceEventDto;
import com.gk.panda.apis.entity.eventtodo.dto.EventToDoListDto;
import com.gk.panda.apis.entity.eventtodo.dto.EventTodoAppListDto;
import com.gk.panda.apis.entity.eventtodo.dto.HandelEventDto;
import com.gk.panda.apis.entity.eventtodo.vo.EventToDoCountVo;
import com.gk.panda.apis.entity.eventtodo.vo.EventToDoDetailsVo;
import com.gk.panda.apis.entity.eventtodo.vo.EventToDoListByAppVo;
import com.gk.panda.apis.entity.eventtodo.vo.EventToDoListVo;
import com.gk.panda.apis.log.Log;
import com.gk.panda.apis.service.EventTodoService;
import com.gk.panda.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName: EventTodoController
 * @Description: 待办事件
 * @author: Sir.yang
 * @date: 2022/11/4 9:42
 * @version: 1.0
 **/
@RestController
@Api(tags = "待办事件")
@RequestMapping("/edmp/eventTodo")
public class EventTodoController {

    @Autowired
    private EventTodoService eventTodoService;

    @ApiOperation("PC获取待办事件列表上的数据统计")
    @PostMapping("/getCount")
    public Result<EventToDoCountVo> getEventToDoCount(@RequestBody EventToDoListSearchDto dto) {
        return Result.ok(eventTodoService.getEventToDoCount(dto));
    }

    @ApiOperation("获取PC待办事件列表")
    @PostMapping("/list")
    public Result<Page<EventToDoListVo>> getEventToDoList(@RequestBody EventToDoListDto dto) {
        return Result.ok(eventTodoService.getEventToDoList(dto));
    }

    @ApiOperation("PC/APP获取待办事件详情数据")
    @GetMapping("/getDetails/{eventId}")
    public Result<EventToDoDetailsVo> getEventToDoDetails(@PathVariable Integer eventId) {
        return Result.ok(eventTodoService.getEventToDoDetails(eventId));
    }

    @ApiOperation("PC完成待办事件")
    @Log
    @PutMapping("/finishEventTodo/{eventId}")
    public Result<String> finishEventTodo(@PathVariable Integer eventId) {
        boolean bool = eventTodoService.finishEventTodo(eventId);
        if (bool) return Result.ok("操作成功");
        return Result.error("操作失败");
    }

    @ApiOperation("PC删除待办事件")
    @Log
    @DeleteMapping("/del/{eventId}")
    public Result<String> deleteEventTodo(@PathVariable Integer eventId) {
        boolean bool = eventTodoService.deleteEventTodo(eventId);
        if (bool) return Result.ok("操作成功");
        return Result.error("操作失败");
    }

    @ApiOperation("PC待办事件批量导出")
    @Log
    @GetMapping("/export")
    public void getBatchExportData(HttpServletResponse response) {
        eventTodoService.exportEventTodo(response);
    }

    /**
     * ----------------------------APP------------------------
     **/

    @ApiOperation("App待办事件列表数据统计")
    @PostMapping("/appListCount")
    public Result<Long> getEventToDoListCountForApp(@RequestBody EventTodoAppListDto dto) {
        return Result.ok(eventTodoService.getEventToDoListCountForApp(dto));
    }

    @ApiOperation("App待办事件列表数据获取")
    @PostMapping("/appList")
    public Result<Page<EventToDoListByAppVo>> getEventToDoListForApp(@RequestBody EventTodoAppListDto dto) {
        return Result.ok(eventTodoService.getEventToDoListForApp(dto));
    }

    @ApiOperation("App受理事件")
    @PostMapping("/acceptanceEvent")
    public Result acceptanceEvent(@RequestBody AcceptanceEventDto dto) {
        return Result.ok(eventTodoService.acceptanceEvent(dto));
    }

    @ApiOperation("App事件处理")
    @PostMapping("/handelEvent")
    public Result handelEvent(@RequestBody HandelEventDto dto) {
        return Result.ok(eventTodoService.handelEvent(dto));
    }
}
